<?php
/*
# ------------------------------------------------------------------------
# JA Job Board Package
# ------------------------------------------------------------------------
# Copyright (C) 2004-2010 JoomlArt.com. All Rights Reserved.
# @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
# Author: JoomlArt.com
# Websites: http://www.joomlart.com - http://www.joomlancers.com.
# ------------------------------------------------------------------------
*/

// no direct access
defined('_JEXEC') or die('Restricted access');


/**
 * @package		Joomla
 * @subpackage	jl_profile
 */
class JAJobBoardControllerJAFinance extends JAJobBoardController{
	/*
	* Constructor
     */
    function __construct( $location = array() )
    {
    	
        parent::__construct( $location );      
        // Register Extra tasks
        $this->registerTask( 'add',     'edit' );
        $this->registerTask( 'apply',   'save' );
    }
    
	function display()
	{
		switch ($this->getTask())
		{
			case 'depositsetup':
				{
					JRequest::setVar( 'layout', 'depositsetup'  );	
					break;	
				}
			case 'add':
			case 'edit':
				{
					JRequest::setVar( 'layout', 'editdepositsetup'  );	
					break;					
				}
			default:
				{
					JRequest::setVar( 'layout', 'pmdeposit'  );						
					break;
				}
		}
		
		parent::display();
	}
	
	function save()
	{
		$data=$_POST;
		$obj=new stdClass();
		$id=JRequest::getVar('id',null);
		if($id)$obj->id=$id;
		$obj->name=$data['name'];
		$obj->depositppper=$data['depositppper'];
		$obj->depositppfee=$data['depositppfee'];
		$obj->depositmin=$data['depositmin'];
		$obj->account=$data['account'];
		$obj->mode=$data['mode'];
		$obj->alias=$data['alias'];
		$obj->currency_code=$data['currency_code'];
		$obj->enable=$data['enable'];		
		$error=array();
		if(trim($data['name'])=='')
			$error[]="NAME MUST NOT BE NULL";
		if(trim($data['alias'])=='')
			$error[]="ALIAS MUST NOT BE NULL";
		if(!is_numeric($data['depositppper']))
			$error[]="DEPOSITPPER MUST BE NUMBERIC";
		if(!is_numeric($data['depositppfee']))
			$error[]="DEPOSITPFEE MUST BE NUMBERIC";	
		if(!is_numeric($data['depositppfee']))
			$error[]="DEPOSITPFEE MUST BE NUMBERIC";
		if(!is_numeric($data['depositmin']))
			$error[]="DEPOSITPMIN MUST BE NUMBERIC";				
		if(!is_numeric($data['mode']))
			$error[]="MODE MUST BE NUMBERIC";	
		$count=count($error);
		if($count>0)
		{
			global $mainframe;
			$document = & JFactory::getDocument();
			$viewType = $document->getType();			
	
			$viewName = 'jafinance';
			$layout   = 'editdepositsetup';
			$view 	  = & $this->getView($viewName,$viewType);
			$view->assign('rows', $obj);
			$view->assign('error', $error);	
			$view->setLayout($layout);
			$view->display();					
		}
		else 
		{
			$model = $this->getModel('jafinance');
			if($model->store($obj))
				$this->setRedirect('index.php?option=com_jajobboard&view=jafinance&task=depositsetup',"SUCCESSFULLY SAVE DEPOSIT SETUP");
			else 
				$this->setRedirect('index.php?option=com_jajobboard&view=jafinance&task=depositsetup',"FAILURE TO SAVE DEPOSIT SETUP");
		}
	}
	function cancel()
	{
		$this->setRedirect('index.php?option=com_jajobboard&view=jafinance&task=depositsetup');
	}
	function remove()
	{
		$cids=JRequest::getVar('cid',null);
		if(!$cids)
			$this->setRedirect('index.php?option=com_jajobboard&view=jafinance&task=depositsetup',"YOU MUST SELECT DEPOSIT SETUP");
		else 
		{
			$model = $this->getModel('finance');
			if(!is_array($cids))$cids=array();
			$cid=implode(",",$cids);
			if($model->remove($cid))
				$this->setRedirect('index.php?option=com_jajobboard&view=jafinance&task=depositsetup',"SUCCESSFULLY DELETE DEPOSIT SETUP");
			else 
				$this->setRedirect('index.php?option=com_jajobboard&view=jafinance&task=depositsetup',"FAILURE TO DELETE DEPOSIT SETUP");
		}
	}
	function publishstetup()
	{
		global $mainframe;
		$model = $this->getModel('finance');
		if(!$model->published(1))
		{
			$msg = JText::_( 'FAILURE TO PUBLISH DEPOSIT SETUP' );
		} else {
			$msg = JText::_( 'SUCCESSFULLY PUBLISH DEPOSIT SETUP' );
		}
		
		$mainframe->redirect( 'index.php?option=com_jajobboard&view=jafinance&task=depositsetup', $msg);		
	}
	function unpublishstetup()
	{
		global $mainframe;
		$model = $this->getModel('finance');
		if(!$model->published(0))
		{
			$msg = JText::_( 'FAILURE TO UNPUBLISH DEPOSIT SETUP ' );
		} else {
			$msg = JText::_( 'SUCCESSFULLY UNPUBLISH DEPOSIT SETUP' );
		}
		
		$mainframe->redirect( 'index.php?option=com_jajobboard&view=jafinance&task=depositsetup', $msg);		
	}
	
}
?>